package com.bankcomm.creditcard.redfriday.shop;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.bankcomm.creditcard.redfriday.BaseActivity;
import com.bankcomm.creditcard.redfriday.MainActivity;
import com.bankcomm.creditcard.redfriday.R;
import com.bankcomm.creditcard.redfriday.data.Shop;
import com.bankcomm.creditcard.redfriday.map.baidu.BaiduMapActivity;

public class ShopActivity extends Activity {
	private Shop mShop;
	private TextView mNameTextView;
	private TextView mAddressTextView;
	private TextView mTelTextView;
	private TextView mFavourableInfoTextView;
	private TextView mPresentationTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.shop);

		int index = getIntent().getIntExtra("index",
				BaseActivity.INDEX_SUPERMARKET);
		if (index == BaseActivity.INDEX_FIFTY) {
			findViewById(R.id.shop_logo).setVisibility(View.INVISIBLE);
		}

		final int distance = getIntent().getIntExtra("distance", 1);

		mShop = (Shop) getIntent().getSerializableExtra("shop");

		TextView titleTextView = (TextView) findViewById(R.id.header_title);
		titleTextView.setText(getString(R.string.shop_detail));

		Button backBtn = (Button) findViewById(R.id.header_back);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

		Button homeBtn = (Button) findViewById(R.id.header_home);
		homeBtn.setVisibility(View.VISIBLE);
		homeBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						MainActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
		});

		mNameTextView = (TextView) findViewById(R.id.shop_name);
		mAddressTextView = (TextView) findViewById(R.id.shop_address);
		mTelTextView = (TextView) findViewById(R.id.shop_tel);
		mFavourableInfoTextView = (TextView) findViewById(R.id.shop_favourableInfo);
		mPresentationTextView = (TextView) findViewById(R.id.shop_presentation);

		mNameTextView.setText(mShop.marketTitle);
		mAddressTextView.setText(mShop.address);
		// mTelTextView.setText(mShop.tel);
		// mFavourableInfoTextView.setText(mShop.favourableInfo);
		// mPresentationTextView.setText(mShop.presentation);

		Button mapBtn = (Button) findViewById(R.id.shop_map_btn);
		mapBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						BaiduMapActivity.class);
				ArrayList<Bundle> list = new ArrayList<Bundle>();
				Bundle bundle = new Bundle();
				bundle.putSerializable("shop", mShop);
				list.add(bundle);
				intent.putParcelableArrayListExtra("shops", list);
				intent.putExtra("from", "shop");
				startActivity(intent);
			}
		});

		Button telBtn = (Button) findViewById(R.id.shop_tel_btn);
		telBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setAction(Intent.ACTION_DIAL);
				intent.setData(Uri.parse("tel:10086"));
				startActivity(intent);
			}
		});
	}
}
